package com.StarStudio.DAO;


import com.ruoyi.common.core.Entity.Coupons;
import com.ruoyi.common.core.Entity.CouponsChooseResult;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface CouponsDAO {

    List<Coupons> findCouponsList(Coupons coupons);

//    @Delete("delete from coupons where coupon_id = #{id}")
    @Update("update coupons set del_flag = true")
    void deleteCouponsById(long id);

    @Insert("insert into coupons values (null,#{coupon_name},#{star},#{stock},#{coupon_price},#{market_price},#{main_picture}," +
            "#{exchange_deadline},#{date_use_begin},#{date_use_end},#{available_time},#{place_of_use},#{attention},#{notice},#{update_time},#{service_tel},#{del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "coupon_id",keyColumn = "coupon_id")
    void addCoupons(Coupons coupons);

    @Update("update coupons set coupon_name = #{coupon_name},star = #{star},stock = #{stock},coupon_price = #{coupon_price}," +
            "market_price = #{market_price},main_picture = #{main_picture},exchange_deadline = #{exchange_deadline}," +
            "date_use_begin = #{date_use_begin},date_use_end = #{date_use_end},available_time = #{available_time}," +
            "place_of_use = #{place_of_use},attention = #{attention},notice = #{notice},update_time = #{update_time},service_tel = #{service_tel}, " +
            "del_flag = #{del_flag} where coupon_id = #{coupon_id}")
    void updateCoupons(Coupons coupons);

    @Select("select stock from coupons where coupon_id = #{coupon_id} and del_flag = false")
    int findStockByCouponsId(long coupon_id);

    @Select("select count(*) from coupons where del_flag = false")
    long findAllRecordNumber();

    @Select("select * from coupons where coupon_id = #{id}")
    Coupons findByCoupon_id(long id);

    @Select("select co.* from coupons co, coupons_item cit where co.coupon_id = cit.coupons_id and cit.item_id = #{coupon_item_id}")
    Coupons findByCoupons_item_id(long coupon_item_id);

    @Select("select coupon_id,coupon_name,main_picture,stock from coupons where del_flag = false")
    List<CouponsChooseResult> getCouponsChooseResultList();

    @Select("select nick_name from sys_user where nick_name like concat('%', #{name}, '%')")
    List<String> findLikeStoreName(String name);

    @Update("update coupons set stock = #{newStock} where coupon_id = #{couponsId}")
    void updateStockById(@Param("couponsId") long couponsId,@Param("newStock") int newStock);
}
